package com.wyh.cloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author wyh
 * @version 1.0
 * @date 2021/11/23 17:01
 */
@RestController
public class FlowLimitController {

    @GetMapping("/testA")
    public String testA() {
        return "------testA   " + UUID.randomUUID().toString();
    }

    @GetMapping("/testB")
    public String testB() {
        return "------testB   " + UUID.randomUUID().toString();
    }

    @GetMapping("/testD")
    public String testD() {
        //int a = 10/0;
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "------testD   " + UUID.randomUUID().toString();
    }

    @GetMapping(value = "/testHotKey")
    @SentinelResource(value = "testHotKey", blockHandler = "default_testHotKey")
    public String testHotKey(@RequestParam(value = "p1", required = false) String p1,
                             @RequestParam(value = "p2", required = false) String p2) {
        return "------testHotKey   " + UUID.randomUUID().toString();
    }

    public String default_testHotKey(String p1, String p2, BlockException exception) {
        return "等等再访问 "+p1+"--"+p2+"--"+exception;
    }

}
